// pages/my/myInfo.js
//var card = require("../card/card.js")
const config = require('../../config.js');
var touchMove = require('../card/touchMove.js');
Page({
  data: {
    
    UserInfo:[],
    isHidden:true
  },
  onPostTap: (event) => {
    //target 和 currenTarget
    //target 指的点击的当前组件 而 currenTarget指的是事件捕获的组件

    var postId = event.currentTarget.dataset.postid;
    //页面跳转
    wx.navigateTo({
      url: '../../posts/post-detail/post-detail?id=' + postId,
    })

  },
  click_home: function(e){
    this.setData({
      isHidden: true
    })
  },
  click_news: function(e){
    this.setData({
      isHidden: false
    })
  },


  phoneCall: function (event) {
    console.log(event)
    var telno = event.currentTarget.dataset.telno
    wx.makePhoneCall({
      phoneNumber: telno

    })
  },

  handleImg: function (event) {
    console.log(event)
    var _url = event.target.dataset.url
    wx.previewImage({
      // current: 'String', // 当前显示图片的链接，不填则默认为 urls 的第一张
      urls: [_url],
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },
  onLoad: function (option) {
    var that = this

    var id2=option.opid
    
    that.setData({
      id: id2
            
    })
    var id3 = that.data.id
    console.log("id3"+id3)

    wx.request({
      
      url: 'http://localhost:8080/UserCard/findByUserId?userId=' + id3,
      method: 'GET',
    
      
      success: function (res) {
        var userCardList = res.data.userCardList;
        console.log(userCardList)
        if (userCardList == null) {
          var toastText = '获取数据失败' + res.data.errMsg;

        } else {
          that.setData({
            UserInfo: userCardList
          })
        }
      }
    }),
      wx.request({

      url: 'http://localhost:8080/article/findArticleByAuthorId?authorId=' + id3,
        method: 'GET',


        success: function (res) {
          var articleInfo = res.data.UserArticles;
          console.log(articleInfo)
          if (articleInfo == null) {
            var toastText = '获取数据失败' + res.data.errMsg;

          } else {
            that.setData({
              UserArticles: articleInfo
            })
          }
        }
      })


  },

  scrollTopFun: function (e) {
    var node = this
    wx.getSystemInfo({

      success: function (res) {
        node.setData({
          winHeight: res.windowHeight
        });
      }

    });

    this.animation = wx.createAnimation({
      duration: 500,
      timingFunction: 'linear',
    })


    console.log(e.detail);
    if (e.detail.scrollTop < 300) {//触发gotop的显示条件  

      this.animation.translateY(e.detail.scrollTop).step(10)
      this.setData({
        animation: this.animation.export(),

      })

      var that = this
      if (!(this.data.hide == 'display: none;')) {
        setTimeout(function () {
          that.setData({ scrollTop: 0 }
          )
        }, 100)
      }




    } else {
      this.setData({
        hide: 'display: none;'
      })
      this.animation.translateY(-(this.data.winHeight)).step(10)
      this.setData({
        animation: this.animation.export(),
        transform: 'transition-duration: 1s; transform: translateY(' + (-20) + 'px)',
        scrollTop: 0
      })
    }


  },
  

  mytap: function () {
    console.log('9999999999999999999');
    this.animation.translateY((0)).step(10)
    this.setData({
      transform: 'transition-duration: 1s; transform: translateY(600px)',
      scrollTop: 0

    });
    var that = this
    setTimeout(function () {
      that.setData({ hide: 'display: block', animation: that.animation.export() })
    }, 600)

  },
  onShareAppMessage:function(){
    return {
      title: this.data.UserInfo[0].user.userName + '-----' + this.data.UserInfo[0].comName,
      path: 'pages/idCard/scCard/scCard?opid=' + this.data.id,
      success: function (res) {
        console.log(res)
        wx.getShareInfo()
      },
      fail: function () {
        console.log("转发失败")
      }
    }
    
  }
  ,

  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  }
})